package org.xiaojl.xcloud.tools.eureka.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent;
import org.springframework.cloud.netflix.eureka.server.event.EurekaServerStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import com.netflix.appinfo.InstanceInfo;

/**  
 * <p>Title: EurekaStatusChangeListener</p>  
 *
 * <p>Description: Eureka服务上下线监控<br>
 * 
	EurekaInstanceCanceledEvent 服务下线事件
	EurekaInstanceRegisteredEvent 服务注册事件
	EurekaInstanceRenewedEvent 服务续约事件
	EurekaRegistryAvailableEvent Eureka注册中心启动事件
	EurekaServerStartedEvent Eureka Server启动事件
 * </p>  
 *
 * @author jilong.xiao  
 * @date 2018年5月2日  
 */
@Component
public class EurekaStatusChangeListener {
	private static final Logger log = LoggerFactory.getLogger(EurekaStatusChangeListener.class);
	
	@EventListener
	public void listen(EurekaInstanceCanceledEvent e){
		log.debug(String.format("%s    %s服务下线了", e.getServerId(),e.getAppName()));
	}
	@EventListener
	public void listen(EurekaInstanceRegisteredEvent e){
		InstanceInfo info = e.getInstanceInfo();
		//AUTH-SERVER[172.16.60.168]进行注册
		log.debug(String.format("%s[%s]进行注册", info.getAppName(),info.getIPAddr()));
	}
	@EventListener
	public void listen(EurekaInstanceRenewedEvent e){
		//x6x8-20180227TY:config-server:8010    CONFIG-SERVER服务续约了
		log.debug(String.format("%s    %s服务续约了", e.getServerId(),e.getAppName()));
	}
	@EventListener
	public void listen(EurekaRegistryAvailableEvent e){
		log.debug("Eureka注册中心启动了");
	}
	@EventListener
	public void listen(EurekaServerStartedEvent e){
		log.debug("Eureka服务启动了");
	}
}
